﻿using System;
using System.Reflection;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using AnyOffice.Components;
using AnyOffice.DAL;
using log4net;
using Microsoft.ApplicationBlocks.Data;
namespace AnyOffice.general.mytable
{
    public partial class rest : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string str = string.Empty;
            string str2 = string.Empty;
            DataTable myTable = ApplicationCache.MyTable;
            for (int i = 0; i < myTable.Rows.Count; i++)
            {
                if (Convert.ToInt32(myTable.Rows[i]["ViewType"].ToString()) != 3)
                {
                    if (myTable.Rows[i]["ModulePos"].ToString() == "l")
                    {
                        str = str + myTable.Rows[i]["ModuleId"].ToString() + ",";
                    }
                    else
                    {
                        str2 = str2 + myTable.Rows[i]["ModuleId"].ToString() + ",";
                    }
                }
            }
            if (str.EndsWith(","))
            {
                str = str.Substring(0, str.Length - 1);
            }
            if (str2.EndsWith(","))
            {
                str2 = str2.Substring(0, str2.Length - 1);
            }
            SqlParameter[] commandParameters = new SqlParameter[3];
            commandParameters[0] = new SqlParameter("@MytableLeft", SqlDbType.NVarChar, 200);
            commandParameters[0].Value = str;
            commandParameters[1] = new SqlParameter("@MytableRight", SqlDbType.NVarChar, 200);
            commandParameters[1].Value = str2;
            commandParameters[2] = new SqlParameter("@UserId", SqlDbType.NVarChar, 20);
            commandParameters[2].Value = base.User.Identity.Name;
            string commandText = "UPDATE [dbo].[Users] SET [MytableLeft] = @MytableLeft, [MytableRight] = @MytableRight WHERE [UserId] = @UserId";
            SqlHelper.ExecuteNonQuery(base.Conn, CommandType.Text, commandText, commandParameters);
            UserCache.Update(base.User.Identity.Name);
            base.CloseConn();
            Response.Redirect("index.aspx");
        }

    }
}
